/**s
 * 
 */
package name.yzhu.httpserver.handle;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import name.yzhu.httpserver.HttpRequestType;

/**
 * @author yhzhu
 *
 */
public class HandleMethodeDeclare {
	private String methodName;
	private List<String> parameterNames;
	private List<String> extParameterNames;
	private Set<String>requiredParam;
	private boolean nativeReqeust;
	private boolean nativeResponse;
	private HttpRequestType requestType;
	private boolean isNative;
	
	public static HandleMethodeDeclare getInstance(Method method){
		URLHandleAnno anno = method.getAnnotation(URLHandleAnno.class);
		HandleMethodeDeclare declare = new HandleMethodeDeclare();
		if (!Strings.isNullOrEmpty(anno.extParameters()))
			declare.setExtParameterNames(Splitter.on(',').trimResults().splitToList(anno.extParameters()));
		else
			declare.setExtParameterNames(new ArrayList<String>());
		declare.setMethodName(method.getName());
		if (!Strings.isNullOrEmpty(anno.parameters()))
			declare.setParameterNames(Splitter.on(',').trimResults().splitToList(anno.parameters()));
		else
			declare.setParameterNames(new ArrayList<String>());
		if (!Strings.isNullOrEmpty(anno.required()))
			declare.setRequiredParam(new HashSet<String>(Splitter.on(',').trimResults().splitToList(anno.required())));
		else
			declare.setRequiredParam(new HashSet<String>());
		declare.setNative(anno.isNative());
		declare.setRequestType(HttpRequestType.byValue(anno.requestType()));
		declare.setNativeReqeust(anno.nativeReqeust());
		declare.setNativeResponse(anno.nativeResponse());
		return declare;
	}

	public String getMethodName() {
		return methodName;
	}

	public void setMethodName(String methodName) {
		this.methodName = methodName;
	}

	public List<String> getParameterNames() {
		return parameterNames;
	}

	public void setParameterNames(List<String> parameterNames) {
		this.parameterNames = parameterNames;
	}

	public List<String> getExtParameterNames() {
		return extParameterNames;
	}

	public void setExtParameterNames(List<String> extParameterNames) {
		this.extParameterNames = extParameterNames;
	}

	public HttpRequestType getRequestType() {
		return requestType;
	}

	public void setRequestType(HttpRequestType requestType) {
		this.requestType = requestType;
	}

	public boolean isNative() {
		return isNative;
	}

	public void setNative(boolean isNative) {
		this.isNative = isNative;
	}

	public boolean isNativeReqeust() {
		return nativeReqeust;
	}

	public void setNativeReqeust(boolean nativeReqeust) {
		this.nativeReqeust = nativeReqeust;
	}

	public boolean isNativeResponse() {
		return nativeResponse;
	}

	public void setNativeResponse(boolean nativeResponse) {
		this.nativeResponse = nativeResponse;
	}

	@Override
	public String toString() {
		return "HandleMethodeDeclare [methodName=" + methodName
				+ ", parameterNames=" + parameterNames + ", extParameterNames="
				+ extParameterNames + ", nativeReqeust=" + nativeReqeust
				+ ", nativeResponse=" + nativeResponse + ", requestType="
				+ requestType + ", isNative=" + isNative + "]";
	}

	public Set<String> getRequiredParam() {
		return requiredParam;
	}

	public void setRequiredParam(Set<String> requiredParam) {
		this.requiredParam = requiredParam;
	}

}
